package com.sincebest.fivestar.rest;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.StringUtil;
import com.sincebest.fivestar.common.utils.RestClient;

@Component
public class GameOmsClient {

	private static final Logger log = LoggerFactory.getLogger(GameOmsClient.class);

	public boolean verifyIsHouseOwner(String houseId, String wxId) {
		Map<String, String> paramsMap = new HashMap();
		if (StringUtils.isNotEmpty(houseId)) {
			paramsMap.put("parlorNum", houseId);
		}
		paramsMap.put("wechatNumber", wxId);
		String url = "http://test.sincebest.com/api/parlor/room/whetherOwenr";
		JSONObject json = getRequest(url, paramsMap);
		String isHouseOwner = json.getString("data");
		return Boolean.parseBoolean(isHouseOwner);
	}

	public String getGameInviteLink(String houseId) {
		Map<String, String> paramsMap = new HashMap();
		paramsMap.put("parlorNum", houseId);
		String url = "http://test.sincebest.com/oms-web/parlor/invitationLink";
		JSONObject json = getRequest(url, paramsMap);
		String inviteLink = json.getString("data");
		if (StringUtil.isEmpty(inviteLink)){
			log.error("请求出错，返回结果为"+json.toJSONString());
		}
		return inviteLink;
	}

	public String getGameKickLink(String houseId, String userId, String nickname, String avatar) {
		Map<String, String> paramsMap = new HashMap();
		paramsMap.put("parlorNum", houseId);
		paramsMap.put("userId", userId);
		paramsMap.put("nickname", nickname);
		paramsMap.put("avatar", avatar);
		String url = "http://test.sincebest.com/oms-web/parlor/tirenLink";
		JSONObject json = getRequest(url, paramsMap);
		String kickLink = json.getString("data");
		if (StringUtil.isEmpty(kickLink)){
			log.error("请求出错，返回结果为"+json.toJSONString());
		}
		
		return kickLink;
	}
	
	public void getHouseMembers(String houseId){
		
		Map<String, String> paramsMap = new HashMap();
		paramsMap.put("parlorNum", houseId);
		paramsMap.put("token", "");
		String url = "http://test.sincebest.com/oms-web/parlor/member/getMembers";
		JSONObject json = getRequest(url, paramsMap);
		String memeberList = json.getString("data");
		return;
	}

	private static JSONObject getRequest(String url, Map<String, String> paramsMap) {

		JSONObject resp = RestClient.getJson(url, paramsMap);
		return resp;

	}
}
